//
//  CLVisitorTableViewController.swift
//  CLWeibo
//
//  Created by 陈亮 on 16/7/9.
//  Copyright © 2016年 陈亮. All rights reserved.
//

import UIKit

class CLVisitorTableViewController: UITableViewController {

    //登录表示
    var isLogin :Bool = CLUserAccountViewModel.sharedUserAccount.isLogin
    //访客视图
    var visitorView :CLVisitorView?
    
    //访客视图加载
    override func loadView() {
        if isLogin{
           super.loadView()
            
        }else {
            visitorView = CLVisitorView ()
            view = visitorView
            
            visitorView?.loginClosure = { [weak self] in
                self?.showOAuthLogin()
                
            }
            //创建导航栏按钮
            setUpNavBarButton()
        }
        
    }
    
    
    func setUpNavBarButton (){
     
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginAction")
    }
    override func viewDidLoad() {
        super.viewDidLoad()


    }

    // MARK:  注册按钮点击事件
    func registerAction (){
        print("点击了注册")
        showOAuthLogin()
    }

    // MARK:  登录按钮点击事假
    func loginAction (){
        print("点击了登录按钮")
        showOAuthLogin()
    }
    
    private func showOAuthLogin(){
        let oAuthVC = CLOAuthViewController()
        let nav = UINavigationController(rootViewController: oAuthVC)
        presentViewController(nav, animated: true , completion: nil)
    }
}
